﻿@namespace MudBlazor
@inherits MudComponentBase 
@typeparam T

@if (ColumnType == ColumnType.SelectionCheckBox)
{
    <td class="mud-table-cell @classname" style="@style" @attributes="@UserAttributes">
        <div class="d-flex">
            <MudCheckBox T="bool" Checked="@_isSelected" CheckedChanged="@((v) => CellCheckedChangedAsync(v, Item))" />
        </div>
    </td>  
}
else if (ColumnType == ColumnType.Text)
{
    <td data-label="@computedTitle" class="@classname" style="@style" @attributes="@UserAttributes">
        @if (isEditing)
        {
            if (EditTemplate != null)
            {
                @EditTemplate(Item)
            }
            else
            {
                if (dataType == typeof(string))
                {
                    <MudTextField T="string" Value="@_valueString" ValueChanged="@StringValueChanged" Margin="@Margin.Dense" Style="margin-top:0"
                        Required="true" />
                }
                else if (isNumber)
                {
                    <MudNumericField T="double" Value="@_valueNumber" ValueChanged="@NumberValueChanged" Margin="@Margin.Dense" Style="margin-top:0"
                        Required="true" />
                }
            }
        }
        else
        {
            if (CellTemplate != null)
            {
                @CellTemplate(Item)
            }
            else
            {
                @computedValue
            }
        }
    </td>
}
else if (ColumnType == ColumnType.InlineEditCommand)
{
    <td class="mud-table-cell @classname" style="@style" @attributes="@UserAttributes">
    @if (isEditing)
    {
        <div style="display: flex;">
            <MudTooltip Text="Save">
                <MudIconButton Class="pa-0" Icon="@Icons.Material.Filled.Done" Size="@Size.Small" OnClick="@Save" Disabled="@(!(DataGrid.Validator?.IsValid ?? false))" />
            </MudTooltip>
            @if (DataGrid.CanCancelEdit)
            {
                <MudTooltip Text="Cancel">
                    <MudIconButton Class="pa-0 ml-4" Icon="@Icons.Material.Filled.Close" Size="@Size.Small" OnClick="@CancelAsync" />
                </MudTooltip>
            }
        </div>
    }
    </td>
}